<template>
	<view class="flex-col page">
		<view>
			<view :style="{height:statusBarHeight+'px'}"></view>
			<u-navbar title="搜索" bgColor="#F5F5F5" @leftClick="$nav(2)">	
			</u-navbar>
		</view>
		<view style="background-color: #fff;padding: 20rpx;">
			<u-search @custom="search" @search="search" placeholder="搜索店铺" v-model="keyword"></u-search>
		</view>
		
		
		<view class="flex-col" v-if="list.length > 0">
			<view class="flex-col" v-for="(item,index) in list" :key="index" @click="itemClick(item)">
				<view class="flex-row justify-between items-center m-item">
					
					<view class="left">
						<image class="img" :src="item.doorboard_img"></image>
						<view class="flex-col name-text">
							<text>{{item.merchant_name}}</text>
							<text style="font-size: 26rpx;color: #999;">{{item.cust_addr}}</text>
						</view>
					</view>
					
					
					<view class="right">
						<view>{{item.distance_km}}</view>
					</view>
				</view>
				<view class="line"></view>
			</view>
			
			<u-loadmore margin-top="20" margin-bottom="20" :status="status" icon-type="flower"
				:load-text="loadText" />
		</view>
		
		<view v-else class="flex-col items-center" style="margin-top: 80rpx;">
			<image src="/static/data_empty.png"></image>
			<text style="color: #c0c4cc;">暂无数据</text>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				list:[],
				page:1,
				status: 'loadmore',
				loadText: {
					loadmore: '下拉加载更多...',
					loading: '加载中...',
					nomore: '没有更多数据了...'
				},
			};
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight + 44
			}
		},
		onPullDownRefresh() {
			this.list = [];
			this.page = 1;
			this.getMerchantList();
		},
		onReachBottom() {
			this.getMerchantList();
		},
		methods:{
			search(val){
				// console.log(val)
				this.keyword = val;
				this.list = [];
				this.page = 1;
				this.getMerchantList();
			},
			itemClick(item){
				uni.navigateTo({
					url:'/pages/merchant/merchant_detail?id='+item.merchant_id + '&title='+item.merchant_name
				});
			},
			getMerchantList(){
				let cur = uni.getStorageSync('local')
				this.$request({
					url:'?c=MerchantOffline&a=offlineClassifiedStores',
					type:'post',
					data:{
						lon:cur.lon,
						lat:cur.lat,
						page:this.page,
						limit:10,
						merchant_name:this.keyword
					}
				}).then(res =>{
					uni.stopPullDownRefresh();
					this.status = 'loadmore';
					if (res.data && res.data.length > 0) {
						this.list = [...this.list, ...res.data];
						this.page += 1;
						if (res.data.length < 10) {
							this.status = 'nomore';
						}
					} else {
						this.status = 'nomore';
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.page{
	width: 100%;
	overflow-y: auto;
	overflow-x: hidden;
	height: 100%;
}
.m-item{
	width: 100%;
	background-color: #fff;
	padding: 20rpx;
}
.left{
	display: flex;
	flex-direction: row;
	// justify-content: flex-start;
	width: 80%;
	.img{
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}
	.name-text{
		margin-left: 15rpx;
		width: 100%;
	    flex: 1;
	}
}
.right{
	display: flex;
	width: 20%;
	text-align: center;
	justify-content: flex-end;
	margin-right: 20rpx;
	font-size: 25rpx;
	color: #999;
}
.line{
	border: 1px solid #f5f5f5;
	// margin-top: 25rpx;
}
</style>
